import Mustache from 'mustache'
import { getMustacheData } from './handlers'

export const indexJs = async (apiItems: IApiItem[]) => {
    const data = await getMustacheData(apiItems)

    return Mustache.render(
        `import { useAppContext } from './useAppContext'
{{#data}}
/**
 * {{title}}{{{funcParamsJsDocStr}}}
 */
export const {{method}}{{funcName}}Api = async ({{{funcParamsJs}}}) => {
	const { mario } = await useAppContext()
	const res = await mario.{{methodLower}}({
		url: '{{{url}}}',
		ignoreBaseURL: true,
{{#reqBodyData}}
		data: { {{reqBodyData}} },
{{/reqBodyData}}
	})
	return res
}

{{/data}}
`,
        { data },
    )
}
